<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="file">
  <img src="" alt="">
  <script>
    // 1. 找对象
    // 2. 给input -> change事件
    // 3. 获取上传的文件内容
    // 4. 把blob内容 赋值给 img
    let ipt = document.querySelector('input')
    let img = document.querySelector('img')
    ipt.onchange = function(e) {
      // 上传的文件信息
      const file = e.target.files[0]
      console.log(file);
      // window -> URL.createObjectURL(file)  -> blob -> 临时预览
      const url = window.URL.createObjectURL(file)
      console.log(url);
      img.src = url
    }

  </script>
</body>
</html>